﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
 
using System.Data.Sql;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;
using System.Web.UI.DataVisualization.Charting;
using System.Drawing;
namespace HZ.Supervise.Web.Secondphase.ReportHospital
{
    public partial class SortInfo : BasePage
    {
        private string strhospitalname = "";//医院名称
        private string strMosth = "";//月份
        protected void Page_Load(object sender, EventArgs e)
        {
            strhospitalname = String.IsNullOrEmpty(Request.QueryString["hname"]) ? "" : Request.QueryString["hname"].ToString();
            strMosth = String.IsNullOrEmpty(Request.QueryString["mid"]) ? "" : Request.QueryString["mid"].ToString();
            if (!strMosth.Equals("")) //如果月份为空 参数有误
            {
                BindList();
            }
            else
            {
                Response.Write("<script>history.go(-1);</script>");
            }
        }

        void BindList()
        {
             SuperviseQuery sq = new SuperviseQuery();
            sq.HospitalName=strhospitalname;
            sq.Append="dbo.fun_GetYearMonth(PlanTime)='" + strMosth+"'";
            int t = 0;
            HZ.Supervise.IBLL.IExecuteContext ie = HZ.Supervise.BLLFactory.ExecuteContext();
            ie.QueryObject = new HZ.Supervise.Model.QueryObject()
            {
                //分组字段
                GroupField = GroupByField.PurchaseTimeMonth| GroupByField.SortSource,
                //查询条件
                Query = sq,
                //分组查询字段
                GroupSelectField = GroupFields.PurchaseAmountTotal | GroupFields.WareHouseRate | GroupFields.WareHouseAmountTotal | GroupFields.WareHouseCountTotal | GroupFields.PurchaseCountTotal | GroupFields.DistributeRate,
                //排序字段
                SortField = "PurchaseTimeMonth ASC"
            };

            //将数据填入gridview中
            System.Data.DataTable dt = ie.ExecutePage(0,1, out t);
           
            //显示相应的字段
  
            gvwSortInfo.DataSource = dt;
            gvwSortInfo.DataBind();
            for (int j = 0; j < gvwSortInfo.Rows.Count; j++)
            {
                gvwSortInfo.Rows[j].Cells[0].RowSpan = 2;
                gvwSortInfo.Rows[j + 1].Cells[0].Visible = false;
                gvwSortInfo.Rows[j].Cells[26].RowSpan = 2;
                gvwSortInfo.Rows[j+1].Cells[26].Visible = false;
                j++;
            }
        }
        protected void gvwSortInfo_RowCreated(object sender, GridViewRowEventArgs e)
        {
            #region 合并表头
            switch (e.Row.RowType)
            {
                case DataControlRowType.Header:

                    //取得下拉框的月份


                    //第一行表头
                    TableCellCollection tcHeader = e.Row.Cells;
                    tcHeader.Clear();
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[0].Attributes.Add("colspan", "2"); //跨Row
                    tcHeader[0].Attributes.Add("bgcolor", "LightSteelBlue");
                    //tcHeader[0].Attributes.Add("bgcolor", "white");
                    tcHeader[0].Text = "";
                    //tcHeader.Add(new TableHeaderCell());
                    //tcHeader[1].Attributes.Add("bgcolor", "Red");
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[1].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[1].Text = "1月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[2].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[2].Text = "2月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[3].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[3].Text = "3月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[4].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[4].Text = "4月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[5].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[5].Text = "5月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[6].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[6].Text = "6月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[7].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[7].Text = "7月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[8].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[8].Text = "8月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[9].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[9].Text = "9月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[10].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[10].Text = "10月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[11].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[11].Text = "11月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[12].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[12].Text = "12月";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[13].Attributes.Add("colspan", "2"); //跨Column
                    tcHeader[13].Text = "</th></tr><tr>";



                    //第2行表头
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[14].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[14].Text = "类别";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[15].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[15].Text = "是否基药";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[16].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[16].Text = "采购总金额";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[17].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[17].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[18].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[18].Text = "采购总金额";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[19].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[19].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[20].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[20].Text = "采购总金额";
                    tcHeader.Add(new TableHeaderCell());

                    tcHeader[21].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[21].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[22].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[22].Text = "采购总金额";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[23].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[23].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[24].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[24].Text = "采购总金额";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[25].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[25].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[26].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[26].Text = "采购总金额";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[27].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[27].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[28].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[28].Text = "采购总金额";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[29].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[29].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[30].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[30].Text = "采购总金额";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[31].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[31].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[32].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[32].Text = "采购总金额";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[33].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[33].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[34].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[34].Text = "采购总金额";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[35].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[35].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[36].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[36].Text = "采购总金额";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[37].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[37].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[38].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[38].Text = "采购总金额";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[39].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[39].Text = "采购总数量";

                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[40].Attributes.Add("bgcolor", "Khaki");
                    tcHeader[40].Text = "操作</th></tr><tr>";
                    break;
            }
            #endregion
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {

            BindList();
        }
    }
}
